<%@ page import="java.util.List" %>
<%@ page import="com.qipay.admin.sp.vo.SpUserDTO" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<!-- Modal 查看账号流水-->
<%@ page language="java" contentType="text/html;charset=utf-8" %>
<!-- Modal 新增模态-->
<%
    String spUserDTOSJson = request.getParameter("spUserDTOS");
    List<SpUserDTO>spUserDTOS = JSONObject.parseArray(spUserDTOSJson,SpUserDTO.class);
%>
<div class="modal fade" id="addChongzhiModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title control-label" id="newWhiteIpsModallabel">添加新订单</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="save" method="POST" id="doc-vld-msg">
                    <div class="box-body" id="dvContent">
                        <div class="form-group form-group-md">
                            <label for="spUserId" class="col-sm-3 control-label">选择码商：</label>
                            <div class="col-sm-9">
                                <select id="spUserId" name="spUserId" class="form-control">
                                    <option value="0">所有</option>
                                    <% for (SpUserDTO s : spUserDTOS) {%>
                                    <option value="<%=s.getId()%>" ><%= s.getSpUserName()%>
                                            <%}%>
                                </select>
                            </div>
                        </div>
                        <div class="form-group form-group-md">
                            <label for="money" class="col-sm-3 control-label">金额：</label>
                            <div class="col-sm-9">
                                <input class="form-control" type="" id="money" maxlength="20"
                                       name="money"
                                       data-validation-message="请输入金额" required>
                            </div>
                        </div>
                        <div class="form-group form-group-md">
                            <label for="code" class="col-sm-3 control-label">验证码：</label>
                            <div class="col-sm-9">
                                <input class="form-control" type="" id="code" maxlength="20"
                                       name="code"
                                       data-validation-message="验证码" required>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">放弃</button>
                <button type="button" class="btn btn-primary" id="addChongzhiModalSureBtn">提交</button>
            </div>
        </div>
    </div>
</div>

<script>
    //监听返回name
    $("#addChongzhiModalSureBtn").on("click", function () {
        var spUserId = $.trim($("#spUserId").val()) || "";
        var spUserName = $("#spUserId").find("option:selected").text();
        var money = $.trim($("#money").val()) || "";
        var code = $.trim($("#code").val()) || "";
        if (spUserId == ""|| money =="" || code=="") {
            alert("请输入信息");
            return false;
        }

        var that = this;
        $(that).attr("disabled", "disabled");
        if (confirm("确定给码商"+spUserId+"充值"+money+"元吗？")) {
            $.ajax({
                type: 'POST',
                url: contextPath + "/cp/chongzhi",
                data: { spUserId: spUserId,money: money,code: code,spUserName:spUserName},
                dataType: "json",
                success: function (data) {
                    if (data) {
                        if (data.code == 200) {
                            alert(data.message);
                            window.location.href = "${pageContext.request.contextPath}/index";
                            return;
                        }else {
                            alert(data.message);
                            $("#code").val('')
                        }
                    }
                    $(that).removeAttr("disabled");
                    // $("#spUserId").val('0');
                    // $("#money").val('')
                    // $("#code").val('')
                },
                error: function (error) {
                    console.log(error);
                    alert('服务器异常，请稍后再试！');
                    $(that).removeAttr("disabled");
                }
            })
        }

    });
</script>

